package com.kckj.comm.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @author hang
 * @date 2020-08-10-11:12
 * @description
 */
public class ConvertUtil {

    /**
     * json字符串转对象
     * @param jsonStr
     * @return
     */
    public static Map<String, Object> jsonStrToMap(String jsonStr){

        JSONObject obj= JSON.parseObject(jsonStr);

        Map<String, Object> data =new HashMap<>();
        //循环转换
        Iterator it =obj.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, Object> entry = (Map.Entry<String, Object>) it.next();
            data.put(entry.getKey(), entry.getValue());
        }
        return data;
    }

    /**
     * json数组转list
     * @param jsonStr
     * @return
     */
    /*public static Map<String, Map<String, Object>> jsonArrToListMap(String jsonStr,){
        Map<String, Map<String, Object>> maps = new HashMap<>();
        JSONArray listObjectFifth = JSONObject.parseArray(jsonStr);
        for(Object mapList : listObjectFifth){
            Map<String, Object> mapList1 = (Map<String, Object>) mapList;

        }
        return maps;
    }*/

}
